<?php


namespace app\activity\validate;


use think\Validate;

class ActivityValidate extends Validate
{
    protected $rule = [
        'id'  => ['require','number', 'egt' => 1],
        'classify_id'  => ['require','number', 'egt' => 1],
        'cover' => [ 'length' => '10,500'],
        'carousel' => [ 'length' => '10,500'],
        'sign_start_time' => ['require', 'number', 'lt'  => 'sign_end_time', 'elt' => 'start_time'], // 报名开始 小于 报名结束； 报名开始小于等于活动开始
        'sign_end_time' => ['require', 'number', 'elt' => 'end_time'], //报名结束 小于等于 活动结束
        'start_time' => ['require', 'number', 'lt' => 'end_time'], //   活动开始 小于 活动结束
        'end_time' => ['require', 'number'],
        'sign_limit' => ['require', 'number'],
        'detail_images' => [ 'length' => '0,5000'],
        'address' => ['require', 'length' => '1,40'],
        'text_desc' => ['length' => '1,2000'],
        'longitude' => ['require','length' => '1,30'],
        'latitude' => ['require','length' => '1,30'],
        'title' => ['require', 'length' => '1,40'],
        'items' => ['array'],
        'status'  => ['require','number', 'in' => [-1, 0, 1]],
    ];

    protected $scene = [
        'get'  =>  ['id'],
        'updateStatus' => ['id', 'status'],
        'create' => ['classify_id','cover', 'carousel', 'start_time', 'end_time',
            'sign_start_time', 'sign_end_time', 'sign_limit',  'detail_images',
            'address', 'title','text_desc','longitude', 'latitude'],
    ];


    public function sceneUpdate()
    {
        return $this->only(['id', 'classify_id','cover', 'carousel',  'sign_limit',  'detail_images',
            'address', 'title','text_desc','longitude', 'latitude'])
            ->remove('classify_id', 'require')
            ->remove('title', 'require')
            ->remove('sign_limit', 'require')
            ->remove('address', 'require')
            ->remove('longitude', 'require')
            ->remove('latitude', 'require');
    }

    protected $message = [
        'cover.length' => '选择的图片数量太多',
        'carousel.length' => '选择的图片数量太多',
        'carousel.detail_images' => '选择的图片数量太多',
        'sign_start_time.lt' => '报名开始时间必须小于报名结束时间',
        'sign_start_time.elt' => '报名开始时间必须小于等于活动开始时间',
        'sign_end_time.elt' => '报名结束时间必须小于等于活动结束时间',
        'start_time.lt' => '活动开始时间必须小于活动结束时间',
    ];
}